<?php

/**
 * Description of CheckAuth
 *
 * @author Márlon
 */
class Eagle_Controller_Plugin_CheckAuth extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        $module = $request->getModuleName();
        $controller = $request->getControllerName();
        $action = $request->getActionName();

        if ($controller != "auth"):
            if (!Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_Session("API"))->hasIdentity()):
                $request->setModuleName('default')
                        ->setControllerName('error')
                        ->setActionName('index')
                        ->setDispatched(true);
            endif;
        endif;
    }

}